Saving snapshot of a knowledge base without blocking

ABSTRACT

A consistent snapshot of a large main memory knowledge base is saved to persistent storage without blocking the application for the duration of serializing and writing the knowledge base. Taking the snapshot comprises bringing the knowledge base to a consistent state (in a multithreaded application), using virtual memory facilities to obtain a copy-on-write copy of the knowledge base in memory, and using a separate thread or process to serialize the copy-on-write copy to persistent storage.

CROSS-REFERENCE TO RELATED APPLICATIONS

Not Applicable

INCORPORATION-BY-REFERENCE OF MATERIAL SUBMITTED ON ATTACHED MEDIA

Not Applicable

TECHNICAL FIELD

The present invention relates to management of persistence in knowledgebases in knowledge processing systems.

BACKGROUND OF THE INVENTION

Many knowledge base systems must be running continuously, responding touser queries and updating their knowledge base. Since main memory sizeshave grown tremendously in the last decade or two, it is now feasible tokeep even very large (tens or hundreds of gigabytes) knowledge bases inmain memory. Such main memory based management of a large knowledge baseoffers many benefits, including overhead reduction by several orders ofmagnitude compared to disk-based knowledge bases.

However, all computer systems crash and must be restarted every now andthen due to, e.g., software or hardware failures, power outages, andoperator errors.

It is thus necessary for such systems to save the knowledge base to diskat least periodically. However, linearizing and writing tens or hundredsof gigabytes of complex, usually cyclic data can be quitetime-consuming, generally taking at least several minutes to complete.Furthermore, the consistency of the saved copy must be ensured. This canbe done using either complicated transaction mechanisms as known in thedatabase literature, or by stopping all other activity (or at leastupdates) for the duration of serializing the snapshot.

It is generally not acceptable to stop all activity in interactiveon-line systems for several minutes at a time. On the other hand,transaction mechanisms, especially if they are disk-based, tend to haverather high overhead that affects all operations in the system.

A low-overhead method of saving consistent snapshots of a largeknowledge base in main memory is thus needed, and devices and computersoftware products utilizing such methods could have importantcompetitive advantages.

For an in-depth description of various operating system concepts, suchas virtual memory, address spaces, virtual addresses, pages, processes,threads, scheduling, the mmap function, and the fork function, thereader is referred to the book Uresh Vahalia: UNIX Internals—The NewFrontiers, Prentice Hall, New Jersey, 1996. For an introduction toknowledge bases and knowledge representation, one is referred to R.Brachman and H. Levesque: Knowledge Representation and Reasoning, MorganKaufmann, 2004; H. Helbig: Knowledge Representation and the Semantics ofNatural Language, Springer, 2006; and I. Vlahavas and N. Bassiliades:Parallel, Object-Oriented and Active Knowledge Base Systems, Kluwer,1998. One skilled in the art should understand both knowledge base andknowledge representation concepts and operating system concepts.

BRIEF SUMMARY OF THE INVENTION

A first aspect of the invention is a method for saving a snapshot of alarge knowledge base without blocking, comprising:

-   -   bringing, using a consistent state means in a computer, the        knowledge base to a consistent state;    -   creating, using a copy-on-write means in a computer, a        copy-on-write virtual copy of the knowledge base; and    -   serializing, using a serializing means in a computer, the        virtual copy to persistent storage.

A second aspect of the invention is a computer comprising:

-   -   one or more processors (101), with at least one of the        processors equipped with a virtual memory means (102);    -   a consistent state means (109);    -   a copy-on-write means (108) that makes use of the virtual memory        means to make a virtual copy of a knowledge base brought into a        consistent state using the consistent state means; and    -   a serializing means (110) for serializing the virtual copy of        the knowledge base to persistent storage.

A further aspect of the invention is a computer program product storedon a computer readable medium operable to cause a computer to save asnapshot of a large main memory knowledge base without blocking,comprising:

-   -   computer usable program code means for bringing the knowledge        base to a consistent state;    -   computer usable program code means for creating a copy-on-write        virtual copy of the knowledge base brought to a consistent        state; and    -   computer usable program code means for serializing the virtual        copy to persistent storage.

BRIEF DESCRIPTION OF THE SEVERAL VIEWS OF THE DRAWING(S)

FIG. 1 illustrates a computer system according to an exemplaryembodiment of the invention.

FIG. 2 illustrates the process of taking a snapshot of a knowledge base.

DETAILED DESCRIPTION OF THE INVENTION

In the following detailed description of the preferred embodiments,reference is made to the accompanying drawings which form a part hereof,and in which are shown by way of illustration specific embodiments inwhich the invention may be practiced. It is to be understood that otherembodiments may be utilized and structural changes may be made withoutdeparting from the scope of the present invention.

FIG. 1 illustrates a computer (e.g., cluster, server, desktop, mobiledevice, embedded computer, processor, or ASIC) according to a possibleembodiment of the invention. The computer comprises one or moreprocessors or processor cores (101) equipped with virtual memory means(102). Typically such virtual memory means comprises a TLB (TranslationLookaside Buffer) and mechanisms for mapping virtual memory addressesused by application programs to physical addresses used to accessphysical memory devices. Virtual memory is usually either page-oriented(as in most modern processors) or segmented (as in, e.g., Intel 80286family, though various variants of segmented memory can also be found innewer processors), though other kinds of virtual memory may also beused. Sometimes processors may also comprise one or more of the otherelements of FIG. 1 within the processor; in particular, embeddedprocessors often incorporate some or all of the memory (RAM and/or ROM),and special purpose processors or ASICs may implement some or all of thevarious operational elements (e.g., 108, 109, 110, 111) directly inhardware or using special co-processors or support ships, eitherpartially or fully.

As is known in the art, many processors use a page table (103) to mapvirtual addresses to physical addresses. Usually the page table hasmultiple levels. Some processors also use other mechanisms such as hashtables, or may delegate the actual mapping details to firmware (e.g.,the MIPS architecture used software traps to perform the mapping andload the mapping for a page into the TLB).

Many modern computers support multiprocessing. (114), (115), and (116)illustrate processes or threads. There may be any number of them. Aprocess basically has its own virtual address space (and often adedicated page table) and may comprise one or more threads, whereas athread generally refers to an execution (virtual processor) andtypically has its own stack and execution context. Execution of threadsand processes is usually managed by a scheduler, which is part of theoperating system (111), as is known to one skilled in the art.

Other common elements of a computer include main memory (105), which istypically volatile semiconductor memory in current computers, I/Osubsystem (112), which typically includes non-volatile storage devicessuch as magnetic, optical or semiconductor disks, keyboard, display,speaker, microphone, etc., and a network interface (113), which connectsthe computer to one or more data communications networks, such as theInternet, radio networks, etc. Several physical interfaces may beemployed for the I/O subsystem and the network interface, or they mayshare a single physical interface.

The computer also comprises a knowledge base (106) in main memory. Theknowledge base may be a complete self-contained knowledge base, or itmay be a partition of a larger knowledge base stored, e.g., on adistributed server or a local disk. The knowledge base may also be adelta to larger knowledge base. Here “delta to a knowledge base” means aset of changes that have been made to a larger knowledge base but havenot yet been merged to it; an example would be local changes (additions,deletions, modifications) that have not yet been set to a centralizedserver for merging into a global database. The knowledge base may bevery big (tens or hundreds of gigabytes or even more).

The knowledge base contains knowledge interpretable by one or morecomputer-based application programs, and the data is represented aslogical formulas (e.g., Horn clauses, first order formulas, reifiedformulas), semantic networks, conceptual structures, frames, scripts,plans, or other similar data structures, or their combinations, and mayalso comprise statistical information (such as information used formachine learning, probability information, or weight information).

According to the invention, a virtual copy is created of the knowledgebase using the virtual memory facilities provided by the operatingsystem and the processor. (107) illustrates such a virtual copy. Thevirtual copy is essentially a copy of the knowledge base (106) at thesame virtual address but in either a different address space (e.g., ifin a different process) or at different virtual addresses. When created,the virtual copy shares the same physical memory with the originalknowledge base. However, the virtual copy is created using copy-on-writevirtual memory mappings, such that whenever an address in the originalknowledge base is written, the appropriate memory block (typically avirtual memory page) containing the written address is automaticallycopied, so that even if the knowledge base is modified after making thecopy, such changes are not visible in the virtual copy. Creating suchvirtual copies is very fast and efficient on most current computers, andthey do not consume much excess physical memory, even if the knowledgebase is very large. Only when one copy is written does duplicatephysical memory get allocated for the copy of the written location(typically on a page-by-page basis); if only a small percentage of pagesis written during the lifetime of the virtual copy, then the overallmemory overhead remains low.

The computer also comprises a copy-on-write means (108) for implementingthe making and maintaining of the virtual memory copy, a consistentstate means (109) for bringing the knowledge base to a consistent state,and a serializing means (110) for serializing the knowledge base intopersistent storage. Each of these means may be realized in the variousembodiments as computer readable program code means stored on a computerreadable medium (such as the main memory or any other computer readablemedium, such as a flash memory, magnetic disk, non-volatile memory,optical disk, networked storage, file server, downloadable file, or ascomputer-decodable signals transmitted over a communications network,wired or wireless), as special purpose firmware in an embedded system,as optimized logic on an ASIC, using a dedicated co-processor, within aspecial processor, or in any other suitable manner or form.

FIG. 2 illustrates the method according to the present invention on ageneral level.

(201) indicates the start of taking a snapshot of the knowledge base.

(202) illustrates the actions related to bringing the knowledge base toa consistent state by the consistent state means. What a consistentstate means depends on the type of the knowledge base. If the knowledgebase supports atomic transactions for controlling concurrent access tothe knowledge base, consistent state generally means that eachtransaction is either fully reflected in the knowledge base or not atall. Bringing the knowledge base to a consistent state may involveensuring that no transaction commit is currently executing (or taking alock that prevents further transactions from modifying the database andthen waiting until all active transactions have committed or aborted.The exact method depends on the concurrency control mechanism used withthe knowledge base and whether partial transactions write their changesimmediately to the knowledge base or whether they are kept in aper-transaction delta. In a particularly simple case, assumingtransactions only modify the main database after it is known that theycan commit successfully and that transactions take a mutual exclusionlock called ‘commit_lock’ for the duration of making their updates, thisstep can be just something like:

mutex_lock(commit_lock);

(203) illustrates making a copy-on-write virtual copy of the knowledgebase by the copy-on-write means. In the preferred embodiment underLinux-like operating systems, this step together with creating a newprocess to perform the serialization and writing can be performed usinga single system call:

fork( );

However, on systems that do not support forking a process (withcopy-on-write semantics), such as many versions of the Microsoft Windowsoperating system and many embedded systems, it is necessary to usedifferent mechanisms. If the system supports the mmap function, then itcan be used to create a new virtual mapping for an existing memory area,with copy-on-write semantics. If the knowledge base is stored inconsecutive memory addresses, then something like the following can beused:

int fd = open(tmpfilename, O_RDWR|O_CREAT|O_TRUNC, 0666); size_t length= XXX; off_t offset = 0; void *kb_addr = mmap(NULL, length,PROT_READ|PROT_WRITE,  MAP_PRIVATE, fd, offset); . . . populate theknowledge base . . . . . . . . . bring it to consistent state . . . void*copy_addr = mmap(NULL, length, PROT_READ|PROT_WRITE,  MAP_PRIVATE, fd,offset);

If the knowledge base consists of several non-contiguous memory blocks,then a several mmap calls might be used to initially allocate space forit, and a corresponding number of mmap calls could be used to make avirtual copy (each call using a different offset, such that the rangesin the file do not overlap). The file could be a temporary file, and onsome systems, a file on a special device or file system for temporarymemory mappings that have no disk file to back them.

On Microsoft Windows, the MapViewOfFile function with the FILE_MAP_COPYoption could be used to create memory mappings in an analogous manner.

Other mechanisms for making the virtual copy are also possible. Forexample, in the Mach operating system it would be possible to send thevirtual memory pages containing the knowledge base to another thread orprocess using a message sent to a port. Shared memory can also be usedto implement the virtual copying. In some embodiments the virtual copymay also be made by directly programming the virtual memory means of theprocessor(s). All these embodiments have in common that they make usethe virtual memory means of at least one processor to make the copy,either directly or indirectly through calls (e.g., to the operatingsystem) that use the virtual memory means in at least one processor.

(204) illustrates allowing mutators, that is, operations that modify theoriginal knowledge base to continue. In its simplest form (correspondingto the example for (203) above, it can be just something like:

mutex_unlock(commit_lock);

(205) illustrates serializing the virtual copy and writing it topersistent storage (typically a disk or a network protocol connection toa remote server that will store it in persistent storage; in somedistributed systems, also storage in volatile memory on a different nodemay sometimes suffice) by the serializing means. The serializing andwriting are preferably performed simultaneously, so that there is noneed to store the entire serialized knowledge base in main memory beforewriting it (the serialized representation can be quite large if theknowledge base is tens or hundreds of gigabytes). However, it is alsopossible to do the serialization first and then write the result.

Serializing the knowledge base can be performed using any known methodfor serializing (or linearizing) an object graph or a knowledge base.One possible method that is capable of handling very large object graphsincluding cyclic and shared data is disclosed in the co-owned U.S.patent application Ser. No. 12/360,202 by the same inventor, which isincorporated herein by reference. Another possible serialization methodis the built-in serialization mechanism in the Java programminglanguage.

The serialization in (205) is typically performed using a separateprocess (if the fork function is used). In that case, the virtual copytypically resides in the same virtual memory addresses as the originalknowledge base (but in a different address space). In such embodiments,a standard serialization or linearization function can be used.

If the virtual copy is mapped to different addresses from the originalknowledge base, then special serialization code must be used.Essentially, the serialization process must be changed so that everypointer in the knowledge base that points to another part of theknowledge base must be adjusted to point to the correct address in thevirtual copy (correct address means the address of the same logicalobject (or more precisely, the virtual copy thereof) that the pointerpointed to in the original knowledge base). If the entire knowledge baseis in a contiguous address range, then only an offset (the difference ofthe starting addresses of the virtual copy and the original knowledgebase) needs to be added to each pointer. This can be done, e.g.,whenever reading a pointer during serialization. However, if theknowledge base is not contiguous, then it may be necessary to identifywhich contiguous region of the knowledge base the pointer points to,look up the new address (or difference) for that region, and add thedifference to the pointer. Identifying the contiguous region may beperformed by indexing an array of memory regions (index being, e.g.,“(addr-first_offset)/region_size”), looking it up from any suitableindex data structure, such as an interval tree, or comparing the pointervalues against start and/or end values of special regions such as anursery (young object area), large object area, or a popular objectarea.

Pointers that point out from the knowledge base to, e.g., constant dataor partitions that are not being included in the snapshot need not bemapped in some embodiments.

Pointers here mean any links between objects. They may be, e.g., memoryaddresses, tagged memory addresses, object identifiers, indexes to anarray comprising references to objects, unique object identifiers,persistent object identifiers, or generally object identifiers in adistributed system.

At (206) the snapshot is complete, and the virtual copy can be freed.Freeing would typically be done by exiting the process that performedthe serialization (if the fork function was used to create the virtualcopy), using the munmap function (if mmap was used to create the virtualcopy), or using UnmapViewOfFile (if MapViewOfFile was used to create thevirtual copy), or using any other suitable mechanism for freeing thevirtual copy.

In the application program comprising the knowledge base (106) specialsynchronization or restrictions to modifying the knowledge base are, inmost embodiments, only required while bringing it to consistent state(202) and creating the copy-on-write virtual copy (203). These are bothfairly fast operations (fast enough not to cause problems in interactiveuse). The serialization and writing can take several orders of magnitudelonger for large knowledge bases. Thus, the snapshot can be takenwithout blocking accesses or updates to the knowledge base for anysignificant period and without significantly complicating thetransaction logic (if any) used in the knowledge base. This is a majorimprovement over existing technology, and may even be the criticalenabling factor for some applications using large knowledge bases.

Many variations of the above described embodiments will be available toone skilled in the art without deviating from the essence of theinvention as set out herein and in the claims. In particular, someoperations could be reordered, combined, or interleaved, or executed inparallel, and many of the data structures could be implementeddifferently. When one element, step, or object is specified, in manycases several elements, steps, or objects could equivalently occur.Steps in flowcharts could be implemented, e.g., as state machine states,logic circuits, or optics in hardware components, as instructions,subprograms, or processes executed by a processor, or as a combinationof these and other techniques.

It is to be understood that the aspects and embodiments of the inventiondescribed herein may be used in any combination with each other. Severalof the aspects and embodiments may be combined together to form afurther embodiment of the invention, and not all features, elements, orcharacteristics of an embodiment necessarily appear in otherembodiments. A method, a computer, or a computer program product whichis an aspect of the invention may comprise any number of the embodimentsor elements of the invention described herein. Separate references to“an embodiment” or “one embodiment” refer to particular embodiments orclasses of embodiments (possibly different embodiments in each case),not necessarily all possible embodiments of the invention.

1. A method for saving a snapshot of a large knowledge base withoutblocking, comprising: bringing, using a consistent state means in acomputer, the knowledge base to a consistent state; creating, using acopy-on-write means in a computer, a copy-on-write virtual copy of theknowledge base; and serializing, using a serializing means in acomputer, the virtual copy to persistent storage.
 2. The method of claim1, further comprising: while the serializing is being performed, makingupdates to the knowledge base from other threads or processes.
 3. Themethod of claim 1, wherein bringing the knowledge base to a consistentstate involves taking a global lock that is used to synchronize updatesto the knowledge base during transaction commits.
 4. The method of claim1, wherein creating a copy-on-write virtual copy of the knowledge basecomprises using the fork function.
 5. The method of claim 1, whereincreating a copy-on-write virtual copy of the knowledge base comprisescalling the mmap function one or more times.
 6. The method of claim 1,wherein creating a copy-on-write virtual copy of the knowledge basecomprises calling the MapViewOfFile function one or more times.
 7. Themethod of claim 1, wherein the serialization is performed using aserialization method capable of handling object graphs that comprisecyclic data.
 8. The method of claim 1, wherein the serialization isperformed using the built-in serialization method in Java.
 9. The methodof claim 1, wherein the serializing comprises adjusting pointers so thatthey point to the correct address in the virtual copy.
 10. A computercomprising: one or more processors (101), with at least one of theprocessors equipped with a virtual memory means (102); a consistentstate means (109); a copy-on-write means (108) that makes use of thevirtual memory means to make a virtual copy of a knowledge base broughtinto a consistent state using the consistent state means; and aserializing means (110) for serializing the virtual copy of theknowledge base to persistent storage.
 11. A computer program productstored on a computer readable medium operable to cause a computer tosave a snapshot of a large main memory knowledge base without blocking,comprising: computer usable program code means for bringing theknowledge base to a consistent state; computer usable program code meansfor creating a copy-on-write virtual copy of the knowledge base broughtto a consistent state; and computer usable program code means forserializing the virtual copy to persistent storage.